<% layout('/layouts/default.html', {title: '单项指标展示提交', libs: ['layout', 'dataGrid','inputmask','ueditor','fileupload','validate']}){ %>
<div class="main-content">
    <div class="box box-main">
    <form class="form-horizontal" id="inputForm">
        <#form:hidden path="noticeId" value="${dcSupExamVo.dcSupExamNotice.id}"/>
        <#form:hidden path="examId" value="${dcSupExamVo.dcSupExamNotice.examId}"/>
        <#form:hidden path="scoreStatus" value="${dcSupExamVo.dcSupExamScore.scoreStatus}"/>
        <#form:hidden path="exameOrg" value="${dcSupExamVo.exameOrg}"/>
        <div class="box-body">
            <div class="row">
                <div class="form-unit">${text('基本信息')}</div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span>${text('年度')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <label class="control-label">${dcSupExamVo.dcSupExamNotice.examYear}年</label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <div class="form-group">
                            <label class="control-label col-sm-2" title="">
                                <span class="required hide">*</span> ${text('标题')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-10">
                                <label class="control-label" style="text-align: left">${dcSupExamVo.dcSupExamNotice.noticeTitle}</label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <div class="form-group">
                            <label class="control-label col-sm-2" title="">
                                <span class="required hide">*</span> ${text('内容')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-10">
                                <label class="control-label" style="text-align: left">${dcSupExamVo.dcSupExamNotice.noticeContent}</label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span>${text('报送时限')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <label class="control-label">${text(@DateUtils.formatDate(dcSupExamVo.dcSupExamNotice.noticeEndTime,'yyyy-MM-dd HH:mm:ss'))}</label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="box-body">
        <div class="row">
            <div class="form-unit">${text('指标信息')}</div>
        </div>
        <table id="dxDataGrid"></table>
    </div>
        <div class="box-body">
            <div class="row">
                <div class="form-unit">${text('其他信息')}</div>
            </div>

            <div class="row" style="font-size: 14px">
                <div class="col-xs-12">
                    <div class="form-group">
                        <label class="control-label col-sm-2" title="">
                            <span class="required">*</span> ${text('联系人')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-3">
                            <#form:input  path="contactName" value="${dcSupExamVo.dcSupExamScore.contactName}" readonly="${dcSupExamVo.dcSupExamScore.scoreStatus=='2'}" maxlength="5"  class="form-control required" placeholder="联系人"/>
                        </div>
                    </div>
                </div>
                <div class="col-xs-12">
                    <div class="form-group">
                        <label class="control-label col-sm-2" title="">
                            <span class="required">*</span> ${text('联系人电话')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-3">
                            <#form:input path="contactPhone" value="${dcSupExamVo.dcSupExamScore.contactPhone}" readonly="${dcSupExamVo.dcSupExamScore.scoreStatus=='2'}" maxlength="11" class="form-control required" placeholder="联系电话"/>
                        </div>
                    </div>
                </div>
                <div class="col-xs-12">
                    <div class="form-group">
                        <label class="control-label col-sm-2" title="">
                            <span class="required">*</span> ${text('附件')}：<i class="fa icon-question hide"></i></label>
                        <div class="col-sm-8">
                            <#form:fileupload id="uploadFile" class="required" bizKey="${dcSupExamVo.dcSupExamScore.id}" readonly="${dcSupExamVo.dcSupExamScore.scoreStatus=='2'}"  bizType="dcSupExamScore_file"
                            uploadType="all" />
                        </div>
                    </div>
                </div>

            </div>

        </div>
        <div class="box-footer">
            <div class="row">
                <div class="col-sm-offset-4 col-sm-8">
                    <% if(dcSupExamVo.dcSupExamScore.scoreStatus == '1'){ %>
                    <button type="submit" class="btn btn-sm btn-primary" onclick="subDxScore()"><i class="fa fa-check"></i> ${text('提交分数')}</button>&nbsp;
                    <% } %>
                    <% if(dcSupExamVo.dcSupExamScore.scoreStatus == null||dcSupExamVo.dcSupExamScore.scoreStatus==''){ %>
                    <button type="submit" class="btn btn-sm btn-default" onclick="saveDXScore();"><i class="fa fa-save"></i> ${text('确认分数')}</button>&nbsp;
                    <% } %>
                    <button type="button" class="btn btn-sm btn-default btnList" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
                </div>
            </div>
        </div>
    </form>
</div>
</div>
<% } %>
<script>
    $('#dxDataGrid').dataGrid({
        data: ${toJson(dcSupExamVo.dcSupScoreList)},
        datatype: "local", // 设置本地数据
        editGrid: $("#scoreStatus").val()=='',
        sortableColumn: false, // 列表不允许排序
        showFooter: true, // 是否显示底部合计行
        emptyDataHint: true,
        editGridInitRowNum:0,
        showRownum: false,
        columnModel: [
            {header:'${text("主键")}',hidden: true, name:'id',width:150, align:"left", frozen:true},
            {header:'${text("任务id")}',hidden: true, name:'examId',width:150, align:"left", frozen:true},
            {header:'${text("指标信息表id")}',hidden: true, name:'quotaInfoId',width:150, align:"left", frozen:true},
            {header:'${text("年度")}', name:'examYear', width:80, align:"center"},
            {header:'${text("类别")}',sortable:false, name:'quotaType', index:'a.message_number', width:100, align:"center",formatter: function(val, obj, row, act){
                    return js.getDictLabel(${@DictUtils.getDictListJson('dc_quotaType')}, val, '${text("未知")}', true);
                },unformat: function(val, obj, cell){
                    return obj.colModel.data[obj.rowId]}},
            {header:'${text("序号")}',sortable:false, name:'sortNum', index:'a.task_title', width:50, align:"center"},
            {header:'${text("指标分类")}',sortable:false, name:'quotaClass',hidden: true},
            {header:'${text("目标内容")}',sortable:false, name:'quotaContent', index:'a.task_type_name', width:350, align:"left" },
            {header:'${text("附件")}', name:'fileName',width:300, align:"left", formatter: function(val, obj, row, act){
                    if(row.fileName){
                        var fileId ='/whdc/a/file/download/'+row.fileId
                        return '<a class=" blue" target="_blank" href="'+fileId+'"><i class="fa fa-download"></i> '+row.fileName+' </a>'}else{
                        return '无'
                    }
                }},
            {header:'${text("被考核单位名称")}',hidden: true,sortable:false, name:'exameOrgName', index:'a.task_type_name', width:150, align:"left" },
            {header:'${text("被考核单位编码")}',hidden: true,sortable:false, name:'exameOrg', index:'a.task_type_name', width:150, align:"left" },
            {header:'${text("本年度目标")}',sortable:false, name:'currentYaerGoal', index:'a.task_type_name', width:150, align:"left" },
            {header:'单位',sortable:false, name:'quotaUnit',width:100, align:"left"},
            {header:'权数',sortable:false, name:'quotaWeight',  width:100, align:"left"},
            {header:'备注', name:'remarks', width:150, align:"left"},
            {header: "分数",name: 'quotaScore',edittype:'text',editable:true,width: 100,align: 'center',editoptions:{'class':'form-control required',
                    dataInit: function(element){
                        let rowid=$(element).attr("rowid")
                        let data=$('#dxDataGrid').dataGrid('getRowData', rowid);
                        $(element).attr("inputvalidate","score")
                        $(element).addClass('inputmask').attr({'data-inputmask-alias': "money", 'data-inputmask': "'digits':'3'",'range':'[0,'+data.quotaWeight+']'}).inputmask()
                        $(element).on("input",function (){
                            refreshZpCount();
                        })
                    }
                },unformat: function(val, obj, cell){return $('#'+obj.rowId+'_'+obj.colModel.name, cell).val();},
                formatter: function(val, obj, row, act){
                    if (val==''||typeof val=="undefined"){val=0;}
                    return val.toFixed(3);
                }
            }
        ],
        autoGridHeight: function(){
            return 290;
        },
        onSelectRow: function(id, isSelect, event){

        },
        ajaxSuccess: function(data){
            refreshZpCount();
        }
    });

    function refreshZpCount(){
        let data = $('#dxDataGrid').dataGrid('getRowData');
        let allQuotaWeight=0;
        let allQuotaScore=0;
        for (let i = 0; i < data.length; i++) {
            if (data[i].quotaScore == 'undefined' ||data[i].quotaScore==''){
                continue;
            }
            allQuotaWeight=accAdd(parseFloat(data[i].quotaWeight||0),allQuotaWeight);
            allQuotaScore=accAdd(parseFloat(data[i].quotaScore||0),allQuotaScore);
        }

        $('#dxDataGrid').dataGrid("footerData", "set", {
            "quotaUnit" : "<center><span>汇总：</span></center>",
            "quotaWeight" : "总权数<span>&nbsp;"+parseFloat(allQuotaWeight).toFixed(3)+" &nbsp;</span>分",
            "quotaScore": "总分<span>&nbsp;"+parseFloat(allQuotaScore).toFixed(3)+" &nbsp;</span>分"
        }, false);

    }

    function subDxScore(){
       $("#inputForm").validate({
            submitHandler: function(){
                subScore();
            }
        });
    }

    function subScore(){
        let subData = {
            "dcSupExamNotice.id":$("#noticeId").val(),
            "dcSupExamNotice.examId":$("#examId").val(),
            "dcSupExamScore.contactName":$("#contactName").val(),
            "dcSupExamScore.contactPhone":$("#contactPhone").val(),
            "fileUploadIds":$("#uploadFile").val(),
            "exameOrg":$("#exameOrg").val(),
        };
        js.ajaxSubmit({url:"${ctx}/score/dcSupExamDXZBScore/subDXScore",data:subData,dataType: 'json',callback:function (data){
                if (data.result=="true"){
                    js.showMessage(data.message);
                    location.reload();
                }else {
                    js.showMessage(data.message);
                }
        }})
    }

    function saveScore(){
        let allData =JSON.stringify($('#dxDataGrid').dataGrid('getRowData'));
        let subData = {"dcSupExamSumQuotaDtoListStr":allData,
            "dcSupExamNotice.id":$("#noticeId").val(),
            "dcSupExamNotice.examId":$("#examId").val(),
            "exameOrg":$("#exameOrg").val(),
        };
        js.ajaxSubmit({url:"${ctx}/score/dcSupExamDXZBScore/saveDXScore",data:subData,dataType: 'json',callback:function (data){
                if (data.result=="true"){
                    js.showMessage(data.message);
                    location.reload();
                }else {
                    js.showMessage(data.message);
                }
        }})
    }

    function saveDXScore(){
        $("#inputForm").validate({
            ignore: "#contactName,#contactPhone,#uploadFile",//不验证的元素
            submitHandler: function(form){
                let html=$('#dxDataGrid').find('input[inputvalidate=score]');
                let hasValid=true;
                for (let i = 0; i <html.length; i++) {
                   let has= $("#inputForm").validate().element(html[i]);
                   if (has==false){hasValid=false}
                }
                if (hasValid){
                    saveScore();
                }
            }
        });
    }

    function accAdd(arg1,arg2){
        var r1,r2,m;
        try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
        try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
        m=Math.pow(10,Math.max(r1,r2))
        return (arg1*m+arg2*m)/m
    }

    function accSub(arg1,arg2){
        var r1,r2,m,n;
        try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
        try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
        m=Math.pow(10,Math.max(r1,r2));
        //last modify by deeka
        //动态控制精度长度
        n=(r1>=r2)?r1:r2;
        return ((arg1*m-arg2*m)/m).toFixed(n);
    }

</script>

<script id="fileuploadTpl" type="text/template">//<!--<div>
<#form:fileupload id="{{d.id}}" bizKey="{{d.bizKey}}" bizType="{{d.bizType}}" uploadType="all"
	class="{{d.cssClass}}" isMini="true" preview="true" readonly="{{d.readonly}}"/>
</div>//--></script>
<style>
    .ui-layout-content{
        padding: 0px !important;
    }
    #jqgh_addOrRemoveGrid_rn{
        display: none;
    }
</style>